package com.china08.yxyapi.api.temp;

import java.sql.Date;
import java.time.LocalDate;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.entity.mg.lecture.YxyLecturePrePack;
import com.china08.yxyapi.util.LectureUtil2;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(tags = { "v06", "测试" })
@RestController
public class HuoDongLectureIndexController {
	@Autowired
	private JdbcTemplate template;

	@Autowired
	private MongoTemplate mt;

	@Autowired
	private LectureUtil2 LectureUtil2;

	private String sql = "SELECT tea_id AS tid,tea_name AS tname,school_id AS sid,school_nick AS sname FROM yxy_huodong.yxy_huodong_lecture_result_tea WHERE area_id_district='610203'";

	private String sql1 = "SELECT tea_id AS tid,tea_name AS tname,school_id AS sid,school_nick AS sname FROM yxy_huodong.yxy_huodong_lecture_result_tea WHERE area_id_district='520523'";

	@RequestMapping(value = "/api_yw/temp/huodong/result/reindex", method = RequestMethod.GET)
	public String find() {
		System.out.println("====================================================");
		List<Map<String, Object>> list = template.queryForList(sql);
		for (Map<String, Object> map : list) {
			LectureUtil2.YtActivity(map.get("sid").toString(), map.get("tid").toString(), map.get("tname").toString(),
					map.get("sname").toString());
		}
		System.out.println("=======================结束=============================");
		return "ok";
	}

	@RequestMapping(value = "/api_yw/temp/huodong/result/reindex1", method = RequestMethod.GET)
	public String find1() {
		System.out.println("====================================================");
		List<Map<String, Object>> list = template.queryForList(sql1);
		for (Map<String, Object> map : list) {
			LectureUtil2.JsActivity(map.get("sid").toString(), map.get("tid").toString(), map.get("tname").toString(),
					map.get("sname").toString());
		}
		System.out.println("=======================结束=============================");
		return "ok";
	}

	/**
	 * 金沙重新统计 2018年2月27日 Richard.Wang
	 * 
	 * @return
	 */

	@ApiOperation(value = "金沙重新统计")
	@RequestMapping(value = "/api_yw/temp/huodong/result/reindex_js", method = RequestMethod.GET)
	public String findJs() {
		System.out.println("====================================================");
		// 包含当天 开始时间
		LocalDate start = LocalDate.of(2017, 11, 22);
		// 结束
		LocalDate end = LocalDate.of(2018, 1, 1);
		Date date2 = Date.valueOf(end);
		Date date3 = Date.valueOf(start);

		Criteria criteria = Criteria.where("areaIdDistrict").is("520523").and("createdDate").gt(date3).lt(date2)
				.and("share").is(1).and("status").is(1).and("auditStats").is(1);
		// long c = mt.count(new Query(criteria), YxyLecturePrePack.class);
		List<YxyLecturePrePack> list = mt.find(new Query(criteria), YxyLecturePrePack.class);
		for (YxyLecturePrePack map : list) {
			LectureUtil2.JsActivity(map.getSchoolId(), map.getUserId(), map.getUserNick(), map.getSchoolNick());
			// LectureUtil2.JsActivity(map.get("sid").toString(),
			// map.get("tid").toString(), map.get("tname").toString(),
			// map.get("sname").toString());
		}
		System.out.println("=======================结束=============================");
		return "ok";
	}

}
